package co.edu.unal.satacredito.database.administration.ejb;

import java.net.UnknownHostException;
import java.util.Date;
import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import org.bson.types.ObjectId;

import com.mongodb.MongoException;

import co.edu.unal.satacredito.database.administration.exceptions.DAOException;
import co.edu.unal.satacredito.database.administration.singleton.SingletonDataStore;
import co.edu.unal.satacredito.database.connection.BrandDatastoreFactory;
import co.edu.unal.satacredito.database.connection.TransactionDatastoreFactory;
import co.edu.unal.satacredito.database.dao.BrandMongoDao;
import co.edu.unal.satacredito.database.dao.FileLogMongoDao;
import co.edu.unal.satacredito.database.entity.Brand;
import co.edu.unal.satacredito.database.entity.FileLog;
import co.edu.unal.satacredito.database.entity.exceptions.NonexistentEntityException;
import co.edu.unal.satacredito.database.exception.UnreachableHostException;

/**
 * Session Bean implementation class MonitorDaoEJB
 */
@Stateless
public class FileDaoEJB implements FileDaoEJBLocal, FileDaoEJBRemote {

	private FileLogMongoDao daoF;

	/**
	 * Default constructor.
	 * 
	 * @throws DAOException
	 */
	public FileDaoEJB() throws DAOException {
		this.daoF = new FileLogMongoDao(SingletonDataStore.getInstance()
				.getDataStore());
	}

	public FileLog findFileById(String id) throws DAOException {
		try {
			return daoF.findByFileId(new ObjectId(id));
		} catch (Exception e) {
			throw new DAOException(e.getMessage());
		}
	}

	public List<FileLog> findByDate(Date initDate, Date endDate)
			throws DAOException {
		try {
			return daoF.findByDateRange(initDate, endDate);
		} catch (UnreachableHostException e) {
			throw new DAOException(e.getMessage());
		}
	}

}
